import {
  HTTP
} from '../../utils/http'
let http = new HTTP();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      value: false
    },
    title: {
      type: String,
      value: ""
    },
    imgSrc: {
      type: String,
      value: ""
    },
    isApi:{
      type: Boolean,
      value: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    fileList:[]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 点击替换参考图事件
    onDone(e) {
      this.triggerEvent('onDone', {
        value: ""
      })
    },
    onClose(e) {
        this.triggerEvent('onClose', this.data.imgSrc)
    },
    onAfterRead(e) {
      let that = this
      http.uploadFile({
        url: '/ai/draw/box/upload/pic',
        filePath: e.detail.file.url,
        name: 'file', //后端接收图片的字段名
        success(res) {
          res = JSON.parse(res)
          if (res.code === '0') {
            const data = res.data
            that.setData({imgSrc: data})
          }
        }
      })
    }
  }
})